package com.zhilianbao.leyaogo.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.bql.convenientlog.CLog;
import com.bql.utils.EventManager;
import com.bql.utils.NetworkUtils;
import com.zhilianbao.leyaogo.events.LeEventCode;

import org.greenrobot.eventbus.EventBus;

import cn.zhilianbao.ice.service.IceService;

/**
 * ClassName: NetWorkChangeReceiver <br>
 * Description: 网络状态Receiver<br>
 * Author: Cyarie <br>
 * Created: 2016/11/18 17:02 <br>
 * Update Time：<br>
 * Update Description：<br>
 */
public class NetWorkChangeReceiver extends BroadcastReceiver {

    public static final String TAG = NetWorkChangeReceiver.class.getSimpleName();

    @Override
    public void onReceive(Context context, Intent intent) {
        NetworkUtils.NetWorkType netWorkType = NetworkUtils.getNetworkType(context);
        CLog.i(TAG, "NetWork Changed-----" + netWorkType.name());
        EventBus.getDefault().post(new EventManager(LeEventCode.MSG_CODE_NETWORK_CHANGED, netWorkType));
        if (netWorkType != NetworkUtils.NetWorkType.NO) {
            IceService.getInstance().initIce();
        }
    }
}
